//
//  JMTitleButton.m
//  OC-Sina
//
//  Created by 陈高健 on 15/12/22.
//  Copyright © 2015年 陈高健. All rights reserved.
//

#import "JMTitleButton.h"

//图片与文字之间的间距
#define MARGIN 5

@implementation JMTitleButton

- (void)layoutSubviews{
    [super layoutSubviews];

    //交换图片和文字之间的位置
    self.titleLabel.x = 0;
    self.imageView.x = CGRectGetMaxX(self.titleLabel.frame) + MARGIN;
    
    //整个titileButton的宽度
    self.width = self.titleLabel.width + self.imageView.width + MARGIN;
    //重新设置titleButton的位置
    self.centerX = self.superview.width * 0.5 ;
}

- (void)setTitle:(NSString *)title forState:(UIControlState)state{
    
    [super setTitle:title forState:state];
    [self sizeToFit];
}

- (void)setImage:(UIImage *)image forState:(UIControlState)state{
    
    [super setImage:image forState:state];
    [self sizeToFit];
}

@end
